<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f8f9fa;
        }
        .login-container {
            width: 300px;
            padding: 20px;
            border: 1px solid #ced4da;
            border-radius: 5px;
            background-color: #fff;
        }
    </style>
</head>
<body>
<div class="login-container">
    <h2 class="text-center mb-4">登录系统</h2>
    <form id="loginForm">
        <div class="mb-3">
            <label for="username" class="form-label">用户名</label>
            <input type="text" class="form-control" id="username" required>
        </div>
        <div class="mb-3">
            <label for="password" class="form-label">密码</label>
            <input type="password" class="form-control" id="password" required>
        </div>
        <button type="submit" class="btn btn-primary w-100">登录</button>
    </form>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    $(document).ready(function() {
        $('#loginForm').on('submit', function(event) {
            event.preventDefault();
            var username = $('#username').val();
            var password = $('#password').val();

            $.ajax({
                url: 'https://localhost:8079/user/auth',
                method: 'POST',
                data: {
                    username: username,
                    password: password
                },
                success: function(response) {
                    if (response.code === 200) {
                        alert('Login failed');
                        localStorage.setItem('userData', JSON.stringify(response.data));
                        window.location.href = 'www.baidu.com';
                    } else if (response.code === 500) {
                        alert('Login failed');
                    }
                },
                error: function() {
                    alert('An error occurred while processing your request');
                }
            });
        });
    });
</script>
</body>
</html>